<!--<div id="exchangeRecords"></div>-->
<!--<script>-->
<!--    layui.use(['layer', 'form', 'table', 'admin', 'upload', 'tree', 'laytpl', 'laydate'], function () {-->
<!--        var $ = layui.jquery;-->
<!--        var layer = layui.layer;-->
<!--        var form = layui.form;-->
<!--        var table = layui.table;-->
<!--        var config = layui.config;-->
<!--        var admin = layui.admin;-->
<!--        var upload = layui.upload;-->
<!--        var laytpl = layui.laytpl;-->
<!--        var laydate = layui.laydate;-->
<!--        $('#exchangeRecords').load('components/sell/returnRecords/returnRecords.html');-->
<!--    })-->
<!--</script>-->
<style>

</style>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div id="searchDIV">
                搜索框
            </div>
            <table class="layui-table" id="tableDiv" lay-filter="tableDiv"></table>
        </div>
    </div>
</div>
<!-- 搜查条件框-->
<script type="text/html" id="searchContent">
    <div class="layui-form lay-header">
        <div class="toolbar">
            <div class="layui-form-item lay-query-content" style="height: auto;width: auto">
                <div class="lay-search-box" style="border-bottom: 1px solid #EAEDF3">
                    <div class="layui-inline ">
                        <label class="layui-form-label">版本名称：</label>
                        <div class="layui-input-inline ">
                            <input class="layui-input" name="versionName" id="typeSearch" placeholder="请输入版本名称" lay-filter="type"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label w-auto">类型：</label>
                        <div class="layui-input-inline ">
                            <select class="layui-input" name="type" id="typeSelect"></select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                    lay-submit layui-form-keyDownSearch="true">查询
                            </button>
                            <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="lay-btn-rows">
            <div class="lay-btn-box">
                <div class="lay-btn-lt">
                    <button id="contractBtnAdd" class="layui-btn icon-btn color-reseda">添加</button>
                </div>
                <div class="lay-btn-rt">

                </div>
            </div>
        </div>
    </div>
</script>
<!--退货状态(1.待审核 ，2已完成)-->

<script type="text/html" id="returnTableBar">
    <button class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</button>
    <button class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</button>
    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
</script>
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload', 'tree', 'laytpl', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var syncProductName = "";
        var syncProductId = 0;

        admin.getDictList('typeSelect', 'app_use_type', null, '类型')


        laytpl(searchContent.innerHTML).render({}, function (html) {
            $('#searchDIV').html(html);

            form.render('select')
        });
        table.render({
            elem: '#tableDiv',
            url: config.base + 'enterprise/system/admin/apkVersionManager/list',
            page: true,
            cols: [[
                {type: 'numbers', title: '序号', width: 100},
                {field: 'versionName', title: '版本名称', width: 150},
                {field: 'version', title: '版本号'},
                {field: 'typeName', title: '类型'},
                {field: 'downFileUrl', title: '文件下载地址'},
                {field: 'createTime', title: '创建时间'},
                {
                    align: 'center',
                    toolbar: '#returnTableBar',
                    title: '操作',
                    fixed: 'right',
                    width: 400
                }

            ]]
        })
        $('#contractBtnAdd').click(function () {
            openFormFun()
        })
        form.on('submit(formSubSearchLog)', function (data) {
            table.reload('tableDiv', {
                where: data.field
            })
        })
        form.on('submit(resets)', function (data) {
            table.reload('tableDiv', {
                where: admin.resetSearch(data.field)
            })
        })

        function openToData(event, data) {
            const titles = {
                detail: `查看App版本详情`,
                edit: `编辑App版本详情`,
            };
            admin.formOpen({
                area: '600px',
                offset: '65px',
                title: titles[event],
                path: 'components/system/systemAppForm.html',
                success: function (layero, index) {
                    console.log(123)
                    data.eventType = event
                    data.buttonType = index
                    parentData.data = data
                    parentData.eventType = event
                },
            })
        }

        table.on('tool(tableDiv)', function (obj) {
            var data = obj.data;  // 获取当前行的数据
            var layEvent = obj.event;  // 获取事件名（edit 或 del）
            if (layEvent === 'detail') {
                openToData(layEvent, data)
            } else if (layEvent === 'edit') {  // 点击编辑按钮
                openToData(layEvent, data)
            } else if (layEvent === 'del') {  // 点击编辑按钮
                layer.confirm('是否确认删除', {
                    offset: '65px',
                    skin: 'layui-layer-admin'
                }, function () {
                    admin.req('enterprise/system/admin/apkVersionManager/delete/' + data.id, {}, function (res) {
                        if (res.code == 200) {
                            layer.msg('删除成功')
                            table.reload('tableDiv')
                        } else {
                            layer.msg('删除失败')
                        }
                    }, 'DELETE')
                }, function () {
                });

            }
        });

        function openFormFun() {
            admin.formOpen({
                area: '600px',
                offset: '65px',
                title: '添加App版本',
                path: 'components/system/systemAppForm.html',
            })
        }
    })
</script>